/*******************************************************************************
 *  TextareaElement class
 *******************************************************************************
// TODO: create control for TextareaElement
// example options object
var options = {
    id: 'id',
    name: 'name',
    placeholder: 'placeholder',   
    classes: 'classes',
    value: 'value',
    rules:{
        // validation rules here
        messages: {
            // validation messages here
        }
    }
}

*/

/**
 *  Represents textarea model
 */
var TextareaElement = function(options) {
    
    // this class should extend an Element class
    $.extend(true, this, new Element($('<textarea>')))
    
    // ------------------------------------------------------- settings
    this.defaults = {
    };
    
    var settings = this.prepareSettings(options);
    
    // ------------------------------------------------------- methods
    
    /**
     *  Sets value
     *  @param value
     *  @return class instance
     */
    this.setValue = function(value){
        this.getElement().val(value);
        return this;
    }
    
    // ------------------------------------------------------- element creation
    this.setId(settings.id)
        .addClass(settings.classes)
        .addAttribute('placeholder', settings.placeholder)
        .addClass('span10')
        .setValue(settings.value);
        
    if(settings.disabled==true) this.addAttribute('disabled', true);
        
    // prepares element validation
    if(settings.rules){
        var metaobject = {
            validate: settings.rules
        };

        var metadata = JSON.stringify(metaobject);
        console.log(metadata);
        this.addClass(metadata)
    }
    
    console.log('TextareaElement was created with id = '+this.getId());
}